package liangtWorkSpace.simple;

/**
 * @ClassName Link
 * @Description : java指针实现队列
 * @Author : LiangT
 * @Date : 2020/6/30 20:28
 */
public class Link<T> {
    class Node<T> {
        T t;
        private Node<T> next;
    }

    private Node<T> head;
    private Node<T> prove;

    public Link() {
        head = null;
    }

    /**
     * 入队列
     *
     * @param t
     */
    public void push(T t) {
        if (head == null) {
            head = new Node();
            head.t = t;
            head.next = null;
        } else if (head.next == null) {
            prove = new Node();
            prove.t = t;
            head.next = prove;
        } else {
            Node node = new Node();
            node.t = t;
            prove.next = node;
            prove = node;
        }
    }

    /**
     * 出队列
     *
     * @return
     */
    public T pop() {
        T t = null;
        if (head == null) {
            return null;
        }
        t = head.t;
        head = head.next;
        return t;
    }

    public static void main(String[] args) {
        Link link = new Link();
        link.push("Java");
        link.push("C++");
        link.push("C");
        link.push("Python");
        link.push("GO");
        link.push("C#");
        link.push("PA");
        System.out.println(link.pop());
        System.out.println(link.pop());
        System.out.println(link.pop());
        System.out.println(link.pop());
        System.out.println(link.pop());
        System.out.println(link.pop());
        System.out.println(link.pop());
    }
}
